<!doctype html>
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
	<!-- // <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script> -->
	<script type="text/javascript" src="jquery-2.1.1.js"></script>
	<title>定时器</title>
</head>
<body>

<ul>
    <li>list item 1</li>
    <li>list item 2</li>
    <li>list item 3</li>
    <li>list item 4</li>
    <li>list item 5</li>
  </ul>
  <p>a paragraph</p>

<script type="text/javascript">
  
function Deferred(func) {
  var donelist = [];
  var faillist = [];
  var deferred = {
      done: function(fn) {
        donelist.push(fn);
        return deferred;
      },
      fail: function(fn) {
        faillist.push(fn)
        return deferred;
      },
      resolve: function(data) {
        donelist[0](data);
      },
      reject: function(data) {
        faillist[0](data);
      }
  }
  return deferred;
}


var defer = $.Deferred();

var filtered = defer.then(function(value) {
  return value * 2;
});

filtered.done(function(value) {
  console.log('打印value',value)
});

defer.resolve(5);


</script>
</body>
</html>


